import { getSelfNodeIcon } from "@system/menu/store";
import { handleAction, refreshTable } from ".";
import { businessStatusMapA } from "./store";
import { handleSearchLoading, handleSearchTime } from "@userList/search";
const searchLoading = ref(false);
const resetLoading = ref(false);
export const searchConfig = () => {
  const defineSearch = {
    okText: getProxyT("base.query"),
    cancelText: getProxyT("base.reset"),
    searchLoading,
    resetLoading,
    refreshTableData: async (searchParams: any, type: any) => {
      searchParams.status =
        searchParams.status === "" ? undefined : searchParams.status;
      handleSearchTime(["start_date", "end_date"], searchParams, "YYYY-MM-DD");
      handleSearchLoading(true, type, defineSearch);
      await refreshTable(searchParams);
      handleSearchLoading(false, type, defineSearch);
    },
    extra: () => (
      <>
        {withDirectivePower({
          vNode: (
            <s-button
              type="primary"
              onClick={() => handleAction({ type: "add" })}
              icon={renderIcon(getSelfNodeIcon("businessApi.create"))}
            >
              {$t("base.addBusiness")}
            </s-button>
          ),
          bindingValue: "businessApi.create",
        })}
      </>
    ),
    searchList: [
      {
        label: getProxyT("table59"),
        type: "input",
        model: "name",
        allowClear: true,
        placeholder: getProxyT("placeholder2"),
      },
      {
        label: getProxyT("table68"),
        type: "rangePicker",
        model: "start_end",
        placeholder: computed(() => [$t("base.startDate"), $t("base.endDate")]),
      },
      {
        label: getProxyT("table63"),
        type: "select",
        model: "status",
        placeholder: getProxyT("placeholder3"),
        searchClass: "search-item-width-150",
        allowClear: true,
        options: businessStatusMapA,
      },
    ],
  };
  return defineSearch;
};
